package databinding.demo.ui;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import databinding.demo.R;
import databinding.demo.databinding.ActivityBindSimpleBinding;
import databinding.demo.model.UserInfo;
import databinding.demo.presenter.SimplePresenter;
import databinding.demo.references.SimpleHandler;
import databinding.demo.utils.LogUtils;

/**
 * Created by dengdayi
 * Date: 2017/03/10 13：59
 * DataBind简单布局
 */

public class BindSimpleActivity extends AppCompatActivity {
    private UserInfo userInfo;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityBindSimpleBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_bind_simple);
        userInfo = new UserInfo("王小二", "13978574858");
        //两种方式等同
//        binding.setVariable(BR.user, userInfo);  //setVariable
        binding.setUser(userInfo);
        //事件绑定
        binding.setSimplePresenter(new SimplePresenter() {
            @Override
            public void onSaveClick(UserInfo user) {
                LogUtils.getInstance().logE("登录===" + user.getUserName() + "  ------- " + user.getMobile());
            }
        });

        binding.setSimpleHandler(new SimpleHandler() {
            @Override
            public void onClickFriend(View view) {
                LogUtils.getInstance().logE("注册===" + userInfo.getUserName() + "  ------- " + userInfo.getMobile());
            }
        });

        binding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtils.getInstance().logE("点我");
            }
        });
    }
}
